﻿package crontab

import (
	"database/sql"
	"github.com/gogf/gf/database/gdb"
)

//定时任务
type Crontab struct {
	Id int `orm:"id,primary" json:"id"`
	Name string `orm:"name" json:"name"`
	Uuid int `orm:"uuid" json:"uuid"`
	Spec string `orm:"spec" json:"spec"`
	ScriptId int `orm:"script_id" json:"scriptId"`
	Hosts string `orm:"hosts" json:"hosts"`
	Enabled int `orm:"enabled" json:"enabled"` //状态, 0:启用；1：停止
	Timeout int `json:"timeout" orm:"timeout"`
	Remark string `orm:"remark" json:"remark"`
	UpdateTime     string `orm:"update_time"     json:"updateTime"`      // 更新时间                                          
    UpdateId       int  `orm:"update_id"       json:"updateId"`          // 更新人                                            
    CreateTime     string `orm:"create_time"     json:"createTime"`      // 创建时间                                          
    CreateId       int  `orm:"create_id"       json:"createId"`          // 创建者   

	ScriptName string `json:"scriptName,omitempty" gconv:"scriptName,omitempty"`
	UpdateName string `json:"updateName,omitempty" gconv:"updateName,omitempty"`
	CreateName string `json:"createName,omitempty" gconv:"createName,omitempty"`   
}

// OmitEmpty sets OPTION_OMITEMPTY option for the model, which automatically filers
// the data and where attributes for empty values.
func (r *Crontab) OmitEmpty() *arModel {
	return Model.Data(r).OmitEmpty()
}

// Inserts does "INSERT...INTO..." statement for inserting current object into table.
func (r *Crontab) Insert() (result sql.Result, err error) {
	return Model.Data(r).Insert()
}

// Replace does "REPLACE...INTO..." statement for inserting current object into table.
// If there's already another same record in the table (it checks using primary key or unique index),
// it deletes it and insert this one.
func (r *Crontab) Replace() (result sql.Result, err error) {
	return Model.Data(r).Replace()
}

// Save does "INSERT...INTO..." statement for inserting/updating current object into table.
// It updates the record if there's already another same record in the table
// (it checks using primary key or unique index).
func (r *Crontab) Save() (result sql.Result, err error) {
	return Model.Data(r).Save()
}

// Update does "UPDATE...WHERE..." statement for updating current object from table.
// It updates the record if there's already another same record in the table
// (it checks using primary key or unique index).
func (r *Crontab) Update() (result sql.Result, err error) {
	return Model.Data(r).Where(gdb.GetWhereConditionOfStruct(r)).Update()
}

// Delete does "DELETE FROM...WHERE..." statement for deleting current object from table.
func (r *Crontab) Delete() (result sql.Result, err error) {
	return Model.Where(gdb.GetWhereConditionOfStruct(r)).Delete()
}